<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------

namespace app\common\validate;
use Think\Db;
/**
 * 基础验证器
 */
class Order extends ValidateBase
{
	// 验证规则
    protected $rule = [
        'order_sn'          => 'require',
        'openid'            => 'require',
        'content'           => 'require'
    ];

    // 验证提示
    protected $message = [
        'order_sn.require'    => '订单号必须',
        'content.require'     => '内容必须'
    ];

    protected function check_order_sn($value){
        if(Db::name("Order")->where(["order_sn"=>$value,"shipping_status"=>3,"pay_status"=>1])->count()==0){
            return "订单不存在或不可评论";
        }
        return true;
    }
    // 应用场景
    protected $scene = [
        'saveGoodsComment'  =>  ['order_sn'=>'require|check_order_sn','content'],
        'mini_wechat_payOrder'  => ['order_sn','openid']
    ];
}
